package com.qzsf.backend.controller;

import com.qzsf.backend.common.Result;
import com.qzsf.backend.dto.OrganizerDetailDTO;
import com.qzsf.backend.entity.OrganizerProfile;
import com.qzsf.backend.service.OrganizerService;
import com.qzsf.backend.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/13 14:38 周三
 * @Email 1429278462@qq.com
 * @Remark 组织控制器
 * @Version 1.0
 */
@RestController
@RequestMapping("organizers")
public class OrganizerController {
    @Autowired
    private OrganizerService organizerService;
    @PostMapping
    public Result createOrganizer(@RequestBody OrganizerDetailDTO organizerDetailDto){
        return organizerService.createOrganizer(organizerDetailDto);
    }
    @PutMapping
    public Result updateOrganizer(@RequestBody OrganizerProfile organizerProfile){
        return organizerService.updateOrganizer(organizerProfile);
    }

    @GetMapping("/{id}")
    public Result getUserById(@PathVariable int id){
        return organizerService.getOrganizerProfileById(id);
    }

    @GetMapping
    public Result getAllOrganizerDetail(@RequestParam(required = false) String name,@RequestParam int pageNo, @RequestParam int pageSize){
        return organizerService.getOrganizerInfoDetail(name,pageNo, pageSize);
    }

    @GetMapping("mobile/basic")
    public Result getOrganizerBasicProfile(){
        return organizerService.getOrganizerBasicProfile();
    }

    @GetMapping("mobile/detail")
    public Result getOrganizerDetailProfile(){
        Map<String,Object> map = ThreadLocalUtil.get();
        int id = (int) map.get("id");
        return organizerService.getOrganizerProfileById(id);
    }

    @PostMapping("mobile/detail")
    public Result updateOrganizerProfileMobile(@RequestBody OrganizerProfile organizerProfile){
        Map<String,Object> map = ThreadLocalUtil.get();
        int id = (int) map.get("id");
        organizerProfile.setId(id);
        return organizerService.updateOrganizer(organizerProfile);
    }

    @GetMapping("mobile/all")
    public Result getAllOrganizerProfileMobile(){
        return organizerService.getAllOrganizerProfileMobile();
    }

    @GetMapping("mobile/one/{id}")
    public Result getOneOrganizerProfileMobile(@PathVariable int id){
        return organizerService.getOrganizerProfileById(id);
    }

}
